<?php

namespace app\models;

use yii;
use app\components\BaseActiveRecord;

/**
 * This is the model class for table "{{%favorite}}".
 *
 * @property integer $id
 * @property integer $uid
 * @property integer $aid
 * @property integer $ctime
 */
class Favorite extends BaseActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%favorite}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['uid', 'aid', 'ctime'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uid' => 'Uid',
            'aid' => 'Aid',
            'ctime' => 'Ctime',
        ];
    }

    public static function getIsFavorite($user, $id) {
        if (!$user) {
            return '';
        }

        /* @var $user User */
        if (!$user->getIsStudent()) {
            return ' disabled';
        }

        return static::find()->where(['aid' => $id, 'uid' => $user->id])->count() > 0 ? ' light' : '';
    }
}
